home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / basic / qbnws104.zip / TERM.ZIP / TSRTERM.BAS next >
BASIC Source File  |  1990-09-03  |  21KB  |  496 lines

  1. '*********************  TSRTerm.Bas  - TSR Terminal Program
  2. '   Written by Nash Bly and Dave Cleary
  3.  
  4. '   THIS PROGRAM IS INTENDED TO BE COMPILED TO DISK
  5.  
  6. '   BC TSRTerm /o;
  7. '   LINK /nod /noe /e /far /pack TSRTerm _NoVal STR01024, , nul, PDQComm PDQ
  8. '   Then use Exe2Com for minimum program size!
  9.  
  10.  
  11. '-------- Here are the essential statements for any PDQCom program
  12.  
  13. DEFINT A-Z                                      'don't leave home without it
  14.  
  15. '$INCLUDE: 'PDQDecl'                            'PDQ declares and types
  16. '$INCLUDE: 'CommDecl'                           'PDQCom declares and types
  17.  
  18. DECLARE SUB ScreenSave (ScrnMem%())             'screen save/restore subs
  19. DECLARE SUB ScreenRest (ScrnMem%())
  20. DECLARE SUB VidCfg (Mono%, Page)                'used for screen saves
  21.  
  22.  
  23. '-------- Some variable initializations and a function definition
  24.  
  25.  
  26.     DIM Registers AS RegType                    'type defined in PDQDecl.Bas
  27.     DIM Screen1(1 TO 2000), Screen2(1 TO 2000)  'holds saved screens
  28.  
  29.     ID$ = "TSRTerm 1.1 Press ALT-C to Pop Up."  'TSR ID
  30.  
  31.     One = 1                                     'save a few bytes with
  32.     Bottom = 25                                 'a few integer constants
  33.     Norm = 7                                    'normal print color
  34.     Space = 32                                  'for Chr$(32)
  35.     Inverse = 112                               'inverse print color
  36.     Reset$ = "ATZ" + CHR$(13)                   'reset the modem command
  37.                                                 'and two strings for printing
  38.     Clear$ = STRING$(79, Space)
  39.     Menu$ = "Alt-X-Exit  ALT-D-Dial  Alt-H-HangUp  Alt-E-Echo:On/Off  Alt-L-Log-On/Off"
  40.  
  41.     HotKey = &H82E                              'alt-c is the hot key
  42.  
  43.     DGroup = TSRInstalled(ID$)                  'See if we are allready installed
  44.     IF DGroup THEN GOTO DeInstall               'we are so deinstall
  45.  
  46.     CLS                                         'clear the screen
  47.     GOSUB Menu
  48.     ResRow = 1
  49.     ResCol = 1
  50.     ScreenSave Screen1()                        'save current screen and cursor
  51.  
  52.     CLS
  53.     PRINT ID$                                   'print out TSR ID
  54.  
  55.  
  56.  
  57. '-------- Open the Com Port and check for errors
  58.  
  59.     Comm$ = "COM1:1200,N,8,1,RB512,XON"         'includes an identifier
  60.     ATDial$ = "ATDT"                            'so external config can find
  61.                                                 'and change
  62.     PRINT "Initializing Port - Standby"
  63.  
  64.     Comm$ = RIGHT$(Comm$, 25)                   'take out identifiers
  65.     ATDial$ = RIGHT$(ATDial$, 4)
  66.  
  67.     OpenCom Comm$                               'open the com port
  68.  
  69.     ComErr = ERR                                'remember error number
  70.  
  71.     IF ComErr THEN                              'if there was an open error
  72.         CLS
  73.         PRINT "Sorry, Unable to Open Com Port"  'ever so sorry
  74.         PRINT "Error - "; ERR                   'here's the error code
  75.         CursorOn
  76.         END                                     'terminate execution
  77.  
  78.     ELSE                                        'if no error
  79.         IF ComLoc THEN In$ = ComInput$(ComLoc)  'clear the com input buffer
  80.         Ok = 0                                  'preset flag to not ok
  81.         FOR I = One TO 2                        'reset modem loop 2 trys max
  82.             ComPrint Reset$                     'send modem a reset command
  83.             In$ = ""                            'init the com input string
  84.             Start& = PDQTimer&                  'remember start time
  85.             DO                                  'modem response loop
  86.                 IF ComLoc THEN                  'if any chars in com buffer
  87.                     In$ = In$ + ComInput$(One)  'add them to com input string
  88.                     IF INSTR(In$, "OK") THEN    'if modem responds "OK" then
  89.                         Ok = -1                 'set flag ok true
  90.                         EXIT DO                 'exit modem response loop
  91.                     END IF
  92.                 END IF
  93.             LOOP WHILE PDQTimer& - Start& < 72  'wait for "OK" 4 for seconds
  94.             IF Ok THEN EXIT FOR                 'if Ok then done waiting
  95.         NEXT
  96.  
  97.         IF NOT Ok THEN                          'if no modem response then
  98.             PRINT "WARNING: - No Modem Recognized"  'display a warning
  99.         END IF
  100.  
  101.     END IF
  102.  
  103.     PopUpHere HotKey, ID$                       'this sets up the TSR
  104.     GOTO EndRes                                 'must be after PopUpHere
  105.  
  106. '------- Main Keyboard and Com Port Input Loop
  107.  
  108.  
  109.     BreakOff                                    'disable CTRL-BREAK
  110.     DosRow = CSRLIN
  111.     DosCol = POS(0)
  112.     ScreenSave Screen2()                        'save underlieing screen
  113.  
  114.     ScreenRest Screen1()
  115.     LOCATE ResRow, ResCol                       'pop up TSR screen
  116.     CursorOn                                    'turn on text cursor
  117.  
  118.     DO                                          'com and keyboard input loop
  119.         KeyPress = BIOSInkey                    'get a key press
  120.  
  121.         SELECT CASE KeyPress                    'process key press
  122.         CASE -45                                'if Alt-X pressed
  123.             ResRow = CSRLIN                     'save cursor row
  124.             ResCol = POS(0)                     'save cursor column
  125.             ScreenSave Screen1()                'save TSR screen
  126.             ScreenRest Screen2()                'restore underlieing screen
  127.             LOCATE DosRow, DosCol               'restore cursor
  128.             BreakOn                             'enable CTRL-BREAK
  129.             PopDown                             'Go away
  130.  
  131.         CASE -32                                'if Alt-D pressed
  132.             GOTO Dial                           'dial a phone number
  133.  
  134.         CASE -35                                'if Alt-H pressed
  135.             GOTO HangUp                         'hang up modem
  136.  
  137.         CASE -18                                'if Alt-E pressed
  138.             GOTO Echo                           'toggle screen echo
  139.  
  140.         CASE -38                                'if Alt-L pressed
  141.             GOTO LogFile                        'Open/Close a disk file
  142.  
  143.         CASE 3                                  'if Ctrl-C pressed
  144.             ComPrint CHR$(3)                    'send it to com port only
  145.  
  146.         CASE 13                                 'if RETURN pressed
  147.             ComPrint CHR$(KeyPress)             'send it to com port
  148.             IF EchoOn THEN                      'if screen echo is on then
  149.                 PRINT                           'print CR-LF to screen
  150.                 GOSUB Scroll                    'scroll screen if needed
  151.                 IF LogOn THEN PRINT #1,         'print to it disk if needed
  152.             END IF
  153.  
  154.         CASE IS > 0                             'if any other key pressed
  155.             ComPrint CHR$(KeyPress)             'print to com port
  156.             IF EchoOn THEN                      'if screen echo is on
  157.                 PRINT CHR$(KeyPress);           'print the char on screen
  158.                 GOSUB Scroll                    'scroll screen if needed
  159.                 IF LogOn THEN PRINT #1, CHR$(KeyPress);    'print it to disk
  160.             END IF
  161.  
  162.         CASE ELSE                               'no key, do nothing
  163.         END SELECT
  164.  
  165. GetCom:
  166.  
  167. '------- Com port character input loop
  168.  
  169.  
  170.         DO WHILE ComLoc                         'if com input buffer waiting
  171.             In$ = ComInput$(One)                'input a single character
  172.             IF In$ = CHR$(13) THEN              'if a CR is received then
  173.                 PRINT                           'print CR-LF to the screen
  174.                 IF LogOn THEN PRINT #1,         'print it to disk if needed
  175.             ELSEIF In$ <> CHR$(10) THEN         'if other then LF received
  176.                 PRINT In$;                      'print the char to the screen
  177.                 IF LogOn THEN PRINT #1, In$;    'print it to disk if needed
  178.             END IF
  179.             GOSUB Scroll